import COS from 'cos-js-sdk-v5';
import {
	SECRETID,
	SECRETKEY,
	BUCKET,
	REGION,
	FOLDER
} from '@/api/my-account.js'

let Https = 'https://'

var cos = new COS({
    SecretId: SECRETID,
    SecretKey: SECRETKEY,
	Protocol:'https:',
	UseAccelerate:true
});
// 上传cos
let upLoadCos = function(value){
	const resFile = []
	return new Promise((resolve,reject)=>{
		const files = value.map((item)=>{
			return{
				Bucket:BUCKET,
				Region:REGION,
				Key: `${FOLDER}${item.name}`,
				Body: item, 
			}
		})
		cos.uploadFiles({files})
		.then(res=>{
			res.files.forEach(item=>resFile.push(`${Https}${item.data.Location}`))
			resolve(resFile)
		})
		.catch(err=>{
			reject(err)
		})
	})
}

export {upLoadCos}
